<template>
	<view class="container" v-if="info.title">
		<view class="s-news-title">
			{{info.title}}
		</view>
		<view class="s-sub-info">
			<view class="s-sub-left">
				<text class="s-author">{{info.author}}</text>
				<text>{{info.created_at}}</text>
			</view>
			<view class="s-sub-right">阅读量{{info.reading_quantity}}</view>
		</view>
		<view class="s-news-content">
			<s-feng-parse :content="info.content"></s-feng-parse>
		</view>	
		<view class="s-operate-box">
			<s-tag type="gray" shape="circle" :plain="true" @tap="set_consult_like">
				<image class="icon_image" :src="info.like_number_status?'../../static/images/icon/praise1.png':'../../static/images/icon/praise.png'"></image>
				<text class="s-black" :class="info.like_number_status?'s-primary':''">{{info.like_number}}赞</text>
			</s-tag> 
			<button open-type="share" class="s-share-btn">
				<s-tag type="gray" shape="circle" :plain="true">
					<s-icon name="fenxiang" :size="33" color="#333333"></s-icon>
					<text class="s-black">分享</text>
				</s-tag>
			</button>
		</view>
		<view class="s-cmt-title">精彩评论（{{total}}）</view>
		<view class="s-cmtbox">
			<view class="s-cmt-cell" v-for="(item,index) in consult_list" :key="index" @tap="consult_evaluate_one(item.id)">
				<image :src="item.user_to.avatar_url" class="s-avatar"></image>
				<view class="s-cmt-detail">
					<view class="s-header-box">
						<view class="s-cmt-nickname">{{item.user_to.nick_name}}</view>
					</view>
					<view class="s-cmt-content">
						{{item.content}}
					</view>
					<view class="s-reply-box">
						<s-list-cell bgcolor="#f2f2f2" :size="28" v-for="(it,ind) in item.consult_evaluate_to" :key="ind">  
							<view class="disname">
								<view class="s-reply-nickname">{{it.user_to.nick_name}}</view>
								<view>{{it.content}}</view>
							</view>
						</s-list-cell>
						<s-list-cell bgcolor="#f2f2f2" :size="28">
							<view class="s-flex-1">
								<text>共{{item.consult_evaluate_to_count}}条回复</text>
							</view>
						</s-list-cell>
					</view>
					<view class="s-footer">
						{{item.created_at}}
						<view class="s-primary s-ml" hover-class="opcity" :hover-start-time="150">回复</view>
					</view>
				</view>
			</view>
		</view>
		<s-no-data v-if="consult_list.length<=0&&moreData===false" :fixed="false" :imgUrl="$s.config.getConfig('NoDataImgUrlA')">
			{{$s.config.getConfig('NoDataTitle')}}
		</s-no-data>
		<s-loadmore v-if="moreData"></s-loadmore>
		<s-nomore v-if="consult_list.length>0&&moreData===false"></s-nomore>
		<s-scroll-top :scrollTop="scrollTop"></s-scroll-top>
		<view class="s-operation" @tap="consult_evaluate">
			<view class="s-btn-comment">发表你的评论...</view>
		</view>
	</view>	
</template>

<script>
	export default {
		data() {
			return {
				id:'',//咨询id
				total:0,//评论条数
				scrollTop: 0,
				paging:null,
				moreData:true,
				consult_list:[],//咨询评论列表
				info:{} // 详情数据
			}
		},
		onLoad(options){
			this.id = options.id
		},
		async onShow(){
			await this._onLoad();
		},
		methods: {
			//默认方法
			async _onLoad(){
				this.info = await this.$s.model.consult.getConsultDetail({id:this.id})
				await this.getConsultEvaluateList()
			}, 
			async getConsultEvaluateList(){
				const paging =  this.$s.model.consult.getConsultEvaluateList({id:this.id})
				this.paging = paging
				const res = await paging.getMoreData()
				if (!res) {
					return
				}
				this.consult_list = res.accumulator
				this.moreData = res.moreData
				this.total = res.total || 0
			},
			// 咨询点赞
			async set_consult_like(){
				if(this.info.like_number_status){
					return;
				}
				await this.$s.model.consult.setConsultLike({id:this.id})
				this.info.like_number = this.info.like_number + 1;
				this.info.like_number_status = true;
			},
			//评论跳转
			async consult_evaluate(){
				return await this.$s.uniApi.navigateTo({url:'../consult_evaluate/consult_evaluate?pid=0&id='+this.id});
			},
			async consult_evaluate_one(pid){
				return await this.$s.uniApi.navigateTo({url:'../consult_evaluate_one/consult_evaluate_one?pid='+pid+'&id='+this.id});
			}
		},
		onPageScroll(e) {
			this.scrollTop = e.scrollTop
		},
		//下拉刷新
		async onPullDownRefresh() {
			await this._onLoad()
			uni.stopPullDownRefresh()
		},
		//上拉加载更多
		async onReachBottom() {
			const res = await this.paging.getMoreData()
			if(!res){
				return
			}
			this.consult_list = res.accumulator
			this.moreData = res.moreData
			this.total = res.total || 0
		},
		// 分享
		onShareAppMessage(res) {
			return this.$s.uniApi.onShareAppMessage({path:'pages/consult_detail/consult_detail?id='+this.id})
		}
	}
</script>
 
<style lang="scss" scoped>
@import 'consult_detail.scss';
</style>
